package com.ruoyi.web.controller.baseInfo;

import com.ruoyi.baseInfo.domain.StoresInfo;
import com.ruoyi.baseInfo.service.StoresInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/stores")
public class StoresInfoController  extends BaseController {
    @Autowired
    private StoresInfoService storesInfoService;

    /**
     * 获取门店列表
     */
    @PreAuthorize("@ss.hasPermi('baseInfo:branchStore:list')")
    @GetMapping("/search")
    public TableDataInfo list(StoresInfo storesInfo)
    {
        startPage();
        List<Map<String , Object>> list = storesInfoService.getStoresList(storesInfo);
        return getDataTable(list);
    }

    /**
     * 新增门店列表
     */
    @PreAuthorize("@ss.hasPermi('stores:add')")
    @PostMapping
    public AjaxResult add(@Validated @RequestBody StoresInfo storesInfo)
    {
        storesInfo.setUpdateBy(getUsername());
        return AjaxResult.success(storesInfoService.insertStores(storesInfo));
    }

}
